import {action, observable, runInAction} from "mobx";
import {BaseResInterface, sendGetRequest} from "../../../net";
import {ProductModelInterface} from "../../../net/instance/CommenModelInstance";
import * as _ from "lodash";
import {realm} from "../../../dao";
import {isSameDate} from "../../../util";
import {SpecialSchema} from "../../../dao/model/Special";
import {ProductListStore} from "./productList";

interface SpecialResInterface extends BaseResInterface {
    data: Special[]
}

export interface Special {
    id: number;
    tag?: string;
    banner?: string;
    products: ProductModelInterface[]
}

export class SpecialStore {
    @observable
    specials: Special[] = [];

    constructor() {
    }

    @action.bound
    async getSpecials(categoryId: number) {
        const {data} = await sendGetRequest<SpecialResInterface>("main/getSpecialColumn", {categoryId});
        runInAction(() => {
            this.specials = data;
        });
    }

}

export function getSpecialStoreInstance() {
    return new SpecialStore();
}

const SpecialStoreInstance = getSpecialStoreInstance();
export default SpecialStoreInstance